using System;
using System.Timers;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;

namespace Campus
{
    public abstract class Structure : BaseEntity
    {
        #region Fields and Properties

        //public Texture2D ConstructionTexture { get; protected set; }

        /// <summary>
        /// The list of grid positions relative to this structure's placement point that it occupies.
        /// </summary>
        public List<Vector2> TilesOccupied { get; protected set; }

        /// <summary>
        /// A Vector2 representing the grid position that this structure was placed on.
        /// </summary>
        public Vector2 GridPosition { get; set; }

        #endregion

        #region Constructors

        public Structure(Texture2D texture, Texture2D teamColorTexture, Texture2D constructionTexture, List<Vector2> tilesOccupied, Vector2 origin, Vector2 position, int maxHitPoints, 
                         Player owner, Level level, Dictionary<String, Ability> abilities, 
                         Dictionary<String, AbilitySubMenu> submenus)
                         : base(texture, teamColorTexture, origin, position, maxHitPoints, owner, level, abilities, submenus)
        {
            this.Size = new Vector2(texture.Width, texture.Height);
            
            //this.ConstructionTexture = constructionTexture;
            this.TilesOccupied = tilesOccupied;

            this.m_isUsable = true;

            PlayerOwner.Structures.Add(this);

            m_entitySelectedImage = texture;

            // Probably shouldn't be done in a timer in case the enemy attacks and destroys the structure before it is built...
            //Timer textureChanger = new Timer(m_constructTime);
            //textureChanger.AutoReset = false;
            //textureChanger.Elapsed += new ElapsedEventHandler(delegate(object o, ElapsedEventArgs e)
            //{
            //    Texture = texture;
            //    m_entitySelectedImage = texture;
            //    m_isUsable = true;
            //});
            //textureChanger.Start();
        }

        #endregion

        #region Methods

        public abstract void Update(Player Player);

        protected override void Destroy()
        {
            PlayerOwner.Destroyed.Add(this);
            PlayerOwner.Structures.Remove(this);
        }

        public override Vector2 GetCenter() {
            return Position - Origin + Size / 2;
        }

        #endregion
    }
}
